<?php
namespace  Admin\Controller;
use Think\Controller;
echo "<meta http-equiv='content-type' content='text/html; charset=utf-8'>";
class ClearCacheController extends IndexController{
    public function clear(){
       $this->clearAdmin();
       $this->clearHome();
    }


    public function clearAdmin(){
        $adminCache = dirname(dirname(dirname(__FILE__)))."/Runtime/Cache/Admin/";
        if(!is_dir($adminCache)){
            return false;
        }else{

            $handle= opendir($adminCache);
            if(!readdir($handle)){
               $this-> redirect("Index/index");

            }
            while (false !== ($file = readdir($handle))) {
                if($file=="." || $file==".."){
                    continue;
                }

                $unlinkFile=$adminCache.$file;
                unlink($unlinkFile);
                $this->redirect("Index/index");
            }

        }

    }


    public function clearHome(){
        $adminCache = dirname(dirname(dirname(__FILE__)))."/Runtime/Cache/Home/";
        if(!is_dir($adminCache)){
            return false;
        }else{

            $handle= opendir($adminCache);
            if(!readdir($handle)){
               $this-> redirect("Index/index");
            }
            while (false !== ($file = readdir($handle))) {
                if($file=="." || $file==".."){
                    continue;
                }

                $unlinkFile=$adminCache.$file;
                unlink($unlinkFile);
                $this->redirect("Index/index");
            }

        }

    }

}